Fix "An input component must either have a 'aria-label' attribute..." error when a <label> is present#1230
Fix "An input component must either have a 'aria-label' attribute..." error when a <label> is present#1230Tommy Josépovic (tjosepo) wants to merge 5 commits intomasterfrom
Conversation
🦋 Changeset detectedLatest commit: 871a9a3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for sg-orbit ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for sg-storybook ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
| value: inputValueRef.current | ||
| }); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
I believe this is textbook what React is now recommending NOT to do with useEffect: https://react.dev/reference/react/useEffect#caveats
There was a problem hiding this comment.
Which part specifically are you concerned about?
Logging something in the console is the textbook definition of a side-effect in functional programming.
To check for the presence of a label, we need to access the ref to obtrain the HTMLInputElement. Using a useEffect or a callbackRef are the main ways to do it.
|
I am not sure I understand the use case correctly. Does the following code would print a warning? When there's a
From what I can see by the following test, the issue might be that the Input and the Label are not wrapped within a |
✅ I confirm that using I'll add it to the test scenarios. I didn't know the To me, it still feel like a bug because using a label with <>
<Label htmlFor="test">Label</Label>
<TextInput id="test" />
</>I understand that labels are this is not as easily verifyable as using I think it's a valid trade-off. We can also argue against this change if we prefer people to use the |
|
Thank for the reply Tommy Josépovic (@tjosepo). Yes, the intent is to always use the |
|
Alright! I'll update my PR and go for it. |
Issue: #1229
Summary
Removes the warning "An input component must either have a 'aria-label' attribute..." when a
<label>is present.What I did
I moved the validation logic inside a
useEffectand add a check forisNilOrEmpty(input.labels).I had to modify
isNilOrEmptyto support arrays (and NodeList). Instead of checkingvalue === "", it checksvalue.length === 0(this works for strings, arrays and NodeLists).How to test
Unit tests were added.